<template>
  <div id="unit" class="flex-row">
    <div class="flex" style="flex: 1; width:70%">
      <distribution-gather v-ref:list :row="row" @select-changed="selected"></distribution-gather>
      <distribution-detail v-show='disdetail' v-ref:detail  :data="row" @select-changed="detailselected" style="height:200px"></distribution-detail>
    </div>
    <div style="width:35%" v-if = "modify">
      <modify-distribution :data="modifyrow" v-ref:modifydis></modify-distribution>
    </div>
    <div style="width:35%" v-if = "isShow">
      <change-bill-state :data="billInfo"></change-bill-state>
    </div>
  </div>
</template>
<script>
/**
*发票分配汇总组件
*/
// import AppData from '../../stores/AppData'
export default {
  title: '发票管理',
  data () {
    return {
      isShow: false,
      row: null,
      modify: false,
      billInfo: null,
      disdetail: false,
      modifyrow: null
    }
  },
  watch: {
    'row' (val) {
      if (val && val.id) {
        this.disdetail = true
      }
    }
  },
  methods: {
    selected (obj) {
      this.row = obj.val
      this.modify = true
      this.isShow = false
      this.modifyrow = obj.val
    },
    detailselected (obj) {
      this.modify = false
      this.isShow = true
      this.billInfo = obj.val
    }
  },
  events: {
    'success' (name, row, res) {
      // this.billInfo = null
      this.isShow = false
      this.modify = false
      this.disdetail = false
      this.modifyrow = null
      this.$refs.list.search()
      this.$refs.detail.search()
    },
    'clean' (row) {
      // this.billInfo = null
      this.isShow = false
      this.modify = false
      this.disdetail = false
      this.modifyrow = null
      this.$refs.list.search()
      this.$refs.detail.search()
    },
    'error' (name, row, res) {
      this.billInfo = null
      this.$refs.list.search()
    },
    'add' (type) {
      this.modify = true
      this.isShow = false
      if (type === 'add') {
        this.$refs.modifydis.zzfph = false
        this.modifyrow = this.$refs.modifydis.initModel()
      } else if (type === 'update') {
        this.row = this.row
      }
    }
  }
}
</script>
